package com.xique.door.api.factory;

import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.api.RemoteDeviceService;
import com.xique.door.api.RemoteUserService;
import com.xique.door.api.request.device.RemoteDeviceAddRequest;
import com.xique.door.api.request.device.RemoteDeviceListRequest;
import com.xique.door.api.request.user.RemoteUserListRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author shd
 * @create 2022/3/10 15:28
 */
@Component
public class RemoteDeviceFallbackFactory implements FallbackFactory<RemoteDeviceService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteDeviceFallbackFactory.class);

    @Override
    public RemoteDeviceService create(Throwable throwable) {

        log.error("门禁服务调用失败:{}", throwable.getMessage());

        return new RemoteDeviceService() {

            @Override
            public AjaxResult getDeviceList(RemoteDeviceListRequest request) {
                return AjaxResult.error("获取设备列表信息失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult addDevice(RemoteDeviceAddRequest request) {
                return AjaxResult.error("添加设备信息失败:" + throwable.getMessage());
            }
        };
    }
}
